package com.tycmc.signelectroniccontracts.tools.show;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.tycmc.signelectroniccontracts.R;


/**
 * Created by Administrator on 2017/2/23 0023.
 */

public class ProDialog {
    public Dialog mDialog;
    private AnimationDrawable animationDrawable = null;

    public ProDialog(Context context, String message) {

        LayoutInflater inflater =(LayoutInflater) context.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.progress_view, null);

        TextView text = (TextView) view.findViewById(R.id.progress_message);
        text.setVisibility(TextUtils.isEmpty(message)? View.GONE: View.VISIBLE);
        text.setText(message);
        ImageView loadingImage = (ImageView) view.findViewById(R.id.progress_view);
        loadingImage.setImageResource(R.drawable.loadg);
        animationDrawable = (AnimationDrawable) loadingImage.getDrawable();
        if (animationDrawable != null) {
            animationDrawable.setOneShot(false);
            animationDrawable.start();
        }

        mDialog = new Dialog(context, R.style.DialogLoadingStyle);
        mDialog.setContentView(view);
        mDialog.setCanceledOnTouchOutside(false);

    }



    public void show() {
        if (mDialog != null) {
            mDialog.show();
        }
    }

    public void setCanceledOnTouchOutside(boolean cancel) {
        mDialog.setCanceledOnTouchOutside(cancel);
    }

    public void dismiss() {
        if (mDialog.isShowing()) {
            mDialog.dismiss();
            animationDrawable.stop();
        }
    }

    public boolean isShowing() {
        if (mDialog.isShowing()) {
            return true;
        }
        return false;
    }
}
